package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HomepageResource;
import com.ruoyi.system.service.IHomepageResourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页资源Controller
 * 
 * @author xin
 * @date 2024-04-21
 */
@RestController
@RequestMapping("/system/homepageResource")
public class HomepageResourceController extends BaseController
{
    @Autowired
    private IHomepageResourceService homepageResourceService;

    /**
     * 查询首页资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:homepageResource:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomepageResource homepageResource)
    {
        startPage();
        List<HomepageResource> list = homepageResourceService.selectHomepageResourceList(homepageResource);
        return getDataTable(list);
    }

    /**
     * 导出首页资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:homepageResource:export')")
    @Log(title = "首页资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomepageResource homepageResource)
    {
        List<HomepageResource> list = homepageResourceService.selectHomepageResourceList(homepageResource);
        ExcelUtil<HomepageResource> util = new ExcelUtil<HomepageResource>(HomepageResource.class);
        util.exportExcel(response, list, "首页资源数据");
    }

    /**
     * 获取首页资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:homepageResource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(homepageResourceService.selectHomepageResourceById(id));
    }

    /**
     * 新增首页资源
     */
    @PreAuthorize("@ss.hasPermi('system:homepageResource:add')")
    @Log(title = "首页资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomepageResource homepageResource)
    {
        return toAjax(homepageResourceService.insertHomepageResource(homepageResource));
    }

    /**
     * 修改首页资源
     */
    @PreAuthorize("@ss.hasPermi('system:homepageResource:edit')")
    @Log(title = "首页资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomepageResource homepageResource)
    {
        return toAjax(homepageResourceService.updateHomepageResource(homepageResource));
    }

    /**
     * 删除首页资源
     */
    @PreAuthorize("@ss.hasPermi('system:homepageResource:remove')")
    @Log(title = "首页资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(homepageResourceService.deleteHomepageResourceByIds(ids));
    }
}
